#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/11/27 15:50
# @Author  : Beam
# @Site    : 
# @File    : test.py
# @Software: PyCharm

def __virtual__():
    '''The name of the call'''
    return "returnpost"

def returner(ret):
	import hashlib, time
	import requests
	import json
	key = 'ucuxeyaBusiep6chei5aicohnaeNgei2'  # server端定义提供的key
	key_name = 'auth-key'  # 该值为固定的参数，匹配server端的key
	asset_api = 'http://192.168.0.10:8000/api/asset/'  # 接口url

	ha = hashlib.md5(key.encode('utf-8'))  # 用self.key 做加密验证
	time_span = time.time()
	ha.update(bytes("%s|%f" % (key, time_span), encoding='utf-8'))
	encryption = ha.hexdigest()
	result = "%s|%f" % (encryption, time_span)

	headers = {}
	headers.update({key_name: result})  # 把auth_key()这个方法里返回的字典加入到headers
	# print(headers)
	data = json.dumps(ret,ensure_ascii=False)
	response = requests.get(url=asset_api,headers=headers,data=data)
	print(response.text)
	f = open('/tmp/returner.log', 'a+')
	f.write(str(ret)[1:-1] + '\n')
	f.close()
